package cn.edu.njuit.springbootfilmreview.mapper;

import cn.edu.njuit.springbootfilmreview.dto.MovieInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;

/**
 * @author Administrator
 * @description 针对表【movie_info(影片信息)】的数据库操作Mapper
 * @createDate 2022-05-23 19:35:25
 * @Entity cn.edu.njuit.springbootfilmreview.dto.MovieInfo
 */
@Mapper
public interface MovieInfoMapper extends BaseMapper<MovieInfo> {

    /**
     * 根据演员姓名获取电影
     *
     * @param name
     * @return
     */
    @Select("SELECT\n" +
            "\ta.* \n" +
            "FROM\n" +
            "\tmovie_info a,\n" +
            "\tactor_info b,\n" +
            "\tmovie_actors c \n" +
            "WHERE\n" +
            "\tb.actor_id = c.actor_id \n" +
            "\tAND a.movie_id = c.movie_id \n" +
            "\tAND b.NAME = \"${name}\"\n" +
            "\t")
    List<MovieInfo> getMovieInfoByActorName(String name);


    /**
     * 根据演员姓名获取电影
     *
     * @param page
     * @param name
     * @return
     */
    @Select("SELECT\n" +
            "\ta.* \n" +
            "FROM\n" +
            "\tmovie_info a,\n" +
            "\tactor_info b,\n" +
            "\tmovie_actors c \n" +
            "WHERE\n" +
            "\tb.actor_id = c.actor_id \n" +
            "\tAND a.movie_id = c.movie_id \n" +
            "\tAND b.NAME = \"${name}\"\n" +
            "\t")
    IPage<MovieInfo> getPageMovieInfoByActorName(IPage page, String name);


    /**
     * 根据电影类型获取电影
     *
     * @param page
     * @param movieName
     * @return
     */
    @Select("SELECT\n" +
            "\ta.*  \n" +
            "FROM\n" +
            "\tmovie_info a,\n" +
            "\ttype_info b,\n" +
            "\tmovie_types c \n" +
            "WHERE\n" +
            "\ta.movie_id = c.movie_id \n" +
            "\tAND b.type_id = c.type_id\n" +
            "\tand b.name = \"${movieName}\"\n" +
            "\t")
    IPage<MovieInfo> getPageMovieInfoByMovieType(IPage page, String movieName);


    /**
     * 根据电影类型和电影时间获取电影
     *
     * @param page
     * @param movieType
     * @param movieYear
     * @return
     */
    @Select("SELECT\n" +
            "\ta.*  \n" +
            "FROM\n" +
            "\tmovie_info a,\n" +
            "\ttype_info b,\n" +
            "\tmovie_types c \n" +
            "WHERE\n" +
            "\ta.movie_id = c.movie_id \n" +
            "\tAND b.type_id = c.type_id \n" +
            "\tAND b.NAME = \"${movieType}\" \n" +
            "\tAND a.movie_year = ${movieYear}")
    IPage<MovieInfo> getMovieInfoByMovieTypeAndMovieYear(IPage page, String movieType, Integer movieYear);


    @Select("SELECT\n" +
            "\ta.* \n" +
            "FROM\n" +
            "\tmovie_info a,\n" +
            "\ttype_info b,\n" +
            "\tmovie_types c \n" +
            "WHERE\n" +
            "\ta.movie_id = c.movie_id \n" +
            "\tAND b.type_id = c.type_id \n" +
            "\tAND b.NAME = \"${movieType}\" \n" +
            "\tAND a.movie_year = ${movieYear} \n" +
            "\tAND a.name LIKE  \"%${movieName}%\"")
    IPage<MovieInfo> getMovieInfoByMovieTypeAndMovieYearAndKeyWords(IPage page, String movieType, Integer movieYear,String movieName);
}
